package com.atguigu.gmall.pay.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AliPayMqConfig {
    /**
     * AliPay队列
     */
    @Bean("PayQueue")
    public Queue PayQueue(){
        return QueueBuilder.durable("normal_queue").build();
    }

    /**
     * AliPay交换机
     */
    @Bean("PayExchange")
    public Exchange PayExchange(){
        return ExchangeBuilder.directExchange("pay_exchange").build();
    }

    /**
     * 定义绑定:正常交换机和正常队列绑定
     */
    @Bean
    public Binding normalBinding(@Qualifier("PayQueue") Queue PayQueue,
                                 @Qualifier("PayExchange") Exchange PayExchange){
        return BindingBuilder.bind(PayQueue).to(PayExchange).with("pay.order.zfb").noargs();
    }
}
